#include"usart_proxy.h"
#include"usart_opcodes.h"
#include"imp/wang_debug.h"

namespace OHOS::Usart_Standard{
	
    int UsartAbilityProxy::open(const std::string& name){
		WANG_DEBUG("UsartAbilityProxy::open\n");
		MessageParcel data,reply;
		MessageOption option;
		data.WriteString(name);
		WANG_DEBUG("UsartAbilityProxy::open >> Remote()->SendRequest\n");
		Remote()->SendRequest(OP::OPEN,data,reply,option);
		WANG_DEBUG("UsartAbilityProxy::open <<\n");
		return 0;
	}
	int UsartAbilityProxy::close(const std::string& name){
		MessageParcel data,reply;
		MessageOption option;
		data.WriteString(name);
		Remote()->SendRequest(OP::CLOSE,data,reply,option);
		return 0;
	}
	bool UsartAbilityProxy::is_open(const std::string& name){
		WANG_DEBUG("UsartAbilityProxy::is_open\n");
		MessageParcel data,reply;
		MessageOption option;
		data.WriteString(name);
		WANG_DEBUG("UsartAbilityProxy::is_open >> Remote()->SendRequest\n");
		Remote()->SendRequest(OP::IS_OPEN,data,reply,option);
		bool res=reply.ReadBool();
		WANG_DEBUG("UsartAbilityProxy::is_open << %s\n",(res?"true":"false"));
		return res;
	}

    int UsartAbilityProxy::write(const std::string& name,const std::string& data) {
		MessageParcel _data,reply;
		MessageOption option;
		_data.WriteString(name);
		_data.WriteString(data);
		Remote()->SendRequest(OP::WRITE,_data,reply,option);
		return 0;
	}

	std::string UsartAbilityProxy::read(const std::string& name,size_t bytes) {
		MessageParcel data,reply;
		MessageOption option;
		data.WriteString(name);
		data.WriteInt64(bytes);
		Remote()->SendRequest(OP::READ_NUM,data,reply,option);
		const std::string str=reply.ReadString();
		return str;
	}
	std::string UsartAbilityProxy::readline(const std::string& name) {
		MessageParcel data,reply;
		MessageOption option;
		data.WriteString(name);
		Remote()->SendRequest(OP::READLINE,data,reply,option);
		const std::string str=reply.ReadString();
		return str;
	}

	void UsartAbilityProxy::begin_read_loop(const std::string& name){
		MessageParcel data,reply;
		MessageOption option;
		data.WriteString(name);
		Remote()->SendRequest(OP::LOOP_BEGIN,data,reply,option);
		return;
	}

	void UsartAbilityProxy::end_read_loop(const std::string& name){
		MessageParcel data,reply;
		MessageOption option;
		data.WriteString(name);
		Remote()->SendRequest(OP::LOOP_END,data,reply,option);
		return;
	}

	std::string UsartAbilityProxy::read_from_looper(const std::string& name){
		MessageParcel data,reply;
		MessageOption option;
		data.WriteString(name);
		Remote()->SendRequest(OP::LOOP_READ,data,reply,option);
		const std::string str=reply.ReadString();
		return str;
	}



} // namespace OHOS::Usart_Standard
